﻿<%@ WebHandler Language="C#" Class="linkmanlist" %>

using System;
using System.Web;
using System.Web.SessionState;
using TSqlServer;

public class linkmanlist : IHttpHandler,IReadOnlySessionState {
    
    public void ProcessRequest (HttpContext context) {

        string sid = context.Session["ecrm_uid"].ToString();
        string filtype = context.Request["filtype"].ToString();
        string filvalue = context.Request["filvalue"].ToString();
        
        context.Response.ContentType = "text/plain";
        context.Response.Write(ListMans(sid,filtype,filvalue));
        context.Response.End();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
    
    private string ListMans(string uid,string filtype,string filvalue)
    {
        string result = "<table id=\"alllinkman\" cellSpacing=\"1\" cellPadding=\"0\" width=\"98%\" align=\"center\" border=\"0\" class=\"tablesorter\">";
        result += "<thead>";
        result += "<tr height=26>";
        result += "<th width=40 align=left>序号</th>";
        result += "<th width=70 align=left>姓名</th>";
        result += "<th width=40 align=left>性别</th>";
        result += "<th align=center>公司</th>";
        result += "</tr>";
        result += "</thead>";

        int iRow = 1;
        result += "<tbody>";

        string sSql = "";
        if (filtype == "filname")
        {
            sSql = "select uid,linkman,sex,companyabb from t_linkman where linkman like '%" + filvalue + "%' and inman='" + uid + "' order by iid desc";
        }
        else
        {
            sSql = "select uid,linkman,sex,companyabb from t_linkman where company like '%" + filvalue + "%' and inman='" + uid + "' order by iid desc";
        }
        
        TSqlDBReader myReader = new TSqlDBReader(sSql);
        while (myReader.FDataReader.Read())
        {
            result += "<tr height=26>";
            result += "<td width=40 align=center>" + iRow.ToString() + "</td>";
            result += "<td width=70><a href=\"javascript:;\" onclick=\"getlinkman('" + myReader.FDataReader.GetValue(0).ToString() + "')\">" + myReader.FDataReader.GetValue(1).ToString() + "</a></td>";
            result += "<td width=40 align=center>" + myReader.FDataReader.GetValue(2).ToString() + "</td>";
            result += "<td>" + myReader.FDataReader.GetValue(3).ToString() + "</td>";
            result += "</tr>";
            iRow++;
        }
        myReader.Free();
        result += "<tbody>";

        result += "</table>";
                                                
        result += "<div id=\"pager\" class=\"pager\">";
        result += "<img src=\"./jquery/tablesorter/first.png\" class=\"first\"/>";
        result += "<img src=\"./jquery/tablesorter/prev.png\" class=\"prev\"/>";
        result += "<input type=\"text\" class=\"pagedisplay\"/>";
        result += "<img src=\"./jquery/tablesorter/next.png\" class=\"next\"/>";
        result += "<img src=\"./jquery/tablesorter/last.png\" class=\"last\"/>";
        result += "<select class=\"pagesize\">";
        result += "<option value=\"10\">10</option>";
        result += "<option selected=\"selected\"  value=\"20\">20</option>";
        result += "<option value=\"30\">30</option>";
        result += "<option  value=\"40\">40</option>";
        result += "</select>";
        result += "</div>";
        
        return result;
    }

}